package com.htrq.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.htrq.entity.HRole;
import com.htrq.entity.Page;
import com.htrq.service.HRoleService;

@Controller
@RequestMapping("jsp/sys")
public class HRoleController {
	@Resource
	private HRoleService hrService;

	@RequestMapping("saverole")
	public String saverole(HRole hr) {
		hrService.saverole(hr);
		return null;
	}
	
	@RequestMapping("getAllRoleByPage")
	@ResponseBody
	public String getAllByPage(HttpServletResponse response,Page page) throws IOException{
		String str=JSON.toJSONString(hrService.getAllByPage(page));
		Long count=hrService.getTotal();
		String json="{total:"+count+",root:"+str+"}";
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(json);
		return null;
	}
	@RequestMapping("getAllRole")
	@ResponseBody
	public String getAll(HttpServletResponse response,Page page) throws IOException{
		String str=JSON.toJSONString(hrService.getAll());
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(str);
		return null;
	}
}
